public class Test {
    public static void main(String[] args) {
        Solution s = new Solution();
        int index = 0;
        index = s.mySqrt(2147395599);
        System.out.println(index);
    }
}

class Solution {
    public int mySqrt(int x) {
        //
        if(x == 0){
            return 0;
        }

        int left = 1;
        int right = x;
        int mid = left + (right - left)/2;


        while(left < right){
            mid = left + (right - left + 1)/2;
            if(mid*mid <= x){
                left = mid;
            }else{
                right = mid - 1;
            }
        }
        return right;
    }

}
